/*
               *icon
               *1为勾勾
               *2为叉叉
               *3为问号
               *4为锁
               *5为难过表情
               *6为笑脸表情
               *7为感叹号
               *最多为7不能再多了
               */
// 加入购物车

$(document).on('click', '.addcart', function () {

    var goods_id = $(this).attr("value")
    $.ajax({
        type: "POST",
        url: "addCart?requestName=goods&goods_id=" + goods_id,
        contentType: "application/json",
        datatype: 'json',
        success: function (data) {
            if (data.exist != null) {

                layui.use(['layer', 'form', 'jquery'], function () {
                    var layer = layui.layer
                        , form = layui.form
                        , $ = layui.$;
                    layui.use('layer', function () {
                        layer.msg('您已加购，请勿重新加购', {icon: 6})
                    })
                })
            }
            if (data.success != null) {

                layui.use(['layer', 'form', 'jquery'], function () {
                    var layer = layui.layer
                        , form = layui.form
                        , $ = layui.$;

                    layui.use('layer', function () {
                        layer.msg('您已成功加入购物车', {icon: 1})
                    })
                })
            }
        },
        error: function () {
            alert("error")
        }

    })

})
//个人信息
$("#information").click(function () {

    window.location.href = "information"

})

//商品详情模态框
$(".modal-quick").click(function () {
    var quickValue = $(this).attr("value")

    $.ajax({
        type: "POST",
        url: "showModal?goods_id=" + quickValue,
        contentType: "application/json",
        datatype: 'json',
        success: function (data) {
            var modal = data.modal

            var html = ""
            html = '<div class="row align-items-center">' +
                '<div class="col-lg-5 col-12"> <img style="width:350px;height:300px" class="img-fluid rounded" src="showPhoto?requestName=url1&url1=' + modal.goods_url1 + '" alt="" /> </div>' +
                '<div class="col-lg-7 col-12 mt-5 mt-lg-0">' +
                '<div class="product-details">' +
                '<h1 id="modalTitle" class="h4 mb-0 font-w-6">' + modal.goods_name + '</h1>' +
                '<div class="star-rating mb-4"><i class="las la-star"></i><i class="las la-star"></i><i class="las la-star"></i><i class="las la-star"></i><i class="las la-star"></i>' +
                '</div> <span id="modalDPrice" class="product-price h5 text-red-1">￥' + modal.goods_D_price + ' <del id="modalYprice" class="text-muted h6">￥' + modal.goods_Y_price + '</del></span>' +
                '<ul class="list-unstyled my-3">' +
                '<li><small>交易方式: <span id="modalMode" class="text-green">' + modal.mode + '</span> </small>' +
                '</li>' +
                '<li class="font-w-4"><small>商品类别 :<span id="modalType" class="text-muted">' + modal.goods_type + ', ' + modal.goods_classify + '</span></small>' +
                '</li>' +
                '</ul>' +
                '<p id="modalDetail" class="mb-4 desc">' + modal.goods_detail + '</p>' +
                '<div class="d-sm-flex align-items-center mb-5">' +
                '<div class="d-flex align-items-center mr-sm-4">' +
                '<button class="btn-product btn-product-up"> <i class="las la-minus"></i>' +
                '</button>' +
                '<input class="form-product" type="number" name="form-product" value="1">' +
                '<button class="btn-product btn-product-down"> <i class="las la-plus"></i>' +
                '</button>' +
                '</div>' +
                '<select class="custom-select mt-3 mt-sm-0" id="inputGroupSelect02">' +
                '<option value="' + modal.goods_size + '" selected>' + modal.goods_size + '</option>' +
                '</select>' +
                '</div>' +
                '<div class="d-sm-flex align-items-center mt-5">' +
                '<button class="btn btn-primary btn-animated mr-sm-3 mb-3 mb-sm-0 addcart" value="' + modal.goods_id + '"><i class="las la-shopping-cart mr-2"></i>加入购物车</button>' +
                '<a class="btn btn-animated btn-dark addcollection" href="javascript:void(0);"> <i class="lar la-heart mr-2 ic-1-2x"></i>加入收藏</a>' +
                '</div>' +
                '</div>' +
                '</div>' +
                '</div>'

            $(".modal-body").html(html)

        },
        error: function () {
            alert("error")
        }
    })
})

//立即购买
$(document).on('click', '.purchase', function () {

    var col = $(this).attr("value")
    $.ajax({

        type: "POST",
        url: "",
        contentType: "application/json",
        datatype: 'json',
        success: function (data) {

        },
        error: function () {
            alert("error")
        }

    })
})

//加入收藏
$(document).on('click', '.addcollection', function () {

    var col = $(this).attr("value")
    $.ajax({
        type: "POST",
        url: "addCollection?goods_id=" + col,
        contentType: "application/json",
        datatype: 'json',
        success: function (data) {
            if (data.exist != null) {

                layui.use(['layer', 'form', 'jquery'], function () {
                    var layer = layui.layer
                        , form = layui.form
                        , $ = layui.$;
                    layui.use('layer', function () {
                        layer.msg('您已加入收藏，请勿重新加入收藏', {icon: 6})
                    })
                })
            }
            if (data.success != null) {

                layui.use(['layer', 'form', 'jquery'], function () {
                    var layer = layui.layer
                        , form = layui.form
                        , $ = layui.$;

                    layui.use('layer', function () {
                        layer.msg('您已成功加入收藏', {icon: 1})
                    })
                })
            }
        },
        error: function () {
            alert("error")
        }

    })
})
	
	
  
  
 